var pages = new Array();
var page = 0;
var text = "";

function providePages(){
	text = story_;
    textCont = $('#eigenerContent');

	pages.push(splitText());
	//textCont.html = pages[0].html;
	$('#eigenerContent').html = "lolz";
	//if(!text == ""){
		//	pages.push(splitText());
		//}
	
}
	function splitText(){
	var div = document.createElement("div");
		//div.style.position = "absolute";
		//div.style.visibility = "hidden";
		div.style.width = textCont.clientWidth + "px";
		div.html = text;
		//document.body.appendChild(div);
		textCont.append(div);
		
		if ( div.clientHeight > textCont.clientHeight ) {
			div.style.width = "auto";
			var textWidth = div.clientWidth,
				offsetPercent = (div.clientWidth - div.clientWidth % textCont.clientWidth ) / div.clientWidth,
				lineHeight = div.clientHeight;
			div.html = div.html.substring( 0, parseInt( div.html.length * offsetPercent ) );
			div.style.width = textCont.clientWidth + "px";
			if ( div.clientHeight >= textCont.clientHeight ) {
				offsetPercent = ( textCont.clientHeight + lineHeight ) / div.clientHeight;
				div.html = div.html.substring( 0, parseInt( div.html.length * offsetPercent ) );

				while ( div.clientHeight > textCont.clientHeight ) {
					 div.html = div.html.substring( 0, div.html.length - 1 );

				}
				
			}
		}
	text= text.substring(div.html.length);
	return div;

	}
	function nextPage(){
		if(page < pages.length-1){
			page++;
			textCont.html = pages[page].html;
		}
		if(!text == ""){
			pages.push(splitText());
			if(!text == ""){
				pages.push(splitText());
			}
		}

	}
	
	function lastPage(){
		if(page > 0 ){
			page--;
			textCont.html = pages[page].html;
		}
	}